<?php
/**
 * Process background jobs
 * 
 */


use Orx\Mailer\MailBox\Message\Background\Job;
foreach(User::current()->personalMailers() as $mailer) {
	$jobs = \Fox\Dao::finder(Job::className())
		->where('boxid = ? AND idusr = ?',array($mailer->boxid,$mailer->idusr))
		->find();
	
	
	$box = $mailer->box()->handle();
	
	foreach($jobs as $job) {
		try {
			switch ($job->type) {
				case Job::TYPE_MOVE_TO;
					try {
						if(!$mailer->box()->isFolder('hive')) {
							$box->createFolder('hive');
						}
						//var_dump($box->getNumberByUniqueId(62));
						$box->selectFolder('hive');
						//var_dump($box->getNumberByUniqueId(62));
						//var_dump($box->getMessage(3));
						
						foreach($box as $eky => $message) {
							var_dump($eky,$message->messageId);
						
							//var_dump($message->get);
						}
						
						/*
						if(!$mailer->box()->isFolder($job->params)) {
							$box->createFolder($job->params);
						}
						//$box->selectFolder($job->params);
						var_dump($box->getFolders());
						foreach($box->getFolders() as $folder) {
							foreach($folder as $sub) {
								var_dump($sub);
							} 
						}
						*/
					} catch(Zend_Mail_Storage_Exception $e) {
						var_dump($e);
					}
					
				break;
			}
		} catch(Exception $e) {
			var_dump($e);
			$job->lob = $e->getMessage();
			$job->status = Job::STATUS_ERROR;
			$job->uname = User::current()->getId();
			$job->udate = Job::sqlDateTime(time());
			$job->update();
		}
	}
	
	
}